package com.snail.ron.service;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xueguoping
 * @desc: TODO
 * @date 2022/4/1117:13
 */
@Service
public class BloomFilterService {

    @Autowired
    private RedissonClient redissonClient;

    /**
     * @desc 创建布隆过滤器
     * @author  xuegp
     * @date   2022/4/11 17:18
     * @param filterName 过滤器名称
     * @param expectedInsertions 预测插入数量
     * @param falseProbability 误判率
     * @return
    */
    public <T> RBloomFilter<T> create(String filterName,long expectedInsertions,double falseProbability){
        RBloomFilter<T> bloomFilter = redissonClient.getBloomFilter(filterName);
        bloomFilter.tryInit(expectedInsertions,falseProbability);
        return bloomFilter;
    }
}
